//~ `New testbench
`timescale  1ns / 1ps  

module tb_encode;      

// encode Parameters   
parameter PERIOD  = 10;


// encode Inputs
reg   clk                                  = 1 ;
reg   [1:0]  keyadsel                      = 0 ;
reg wrregen =0;
reg   [127:0]  intxt                       = 0 ;
reg   [127:0]  roundkey                    = 0 ;

// encode Outputs
wire  [127:0]  outtxt                      ;


initial
begin
    forever #(PERIOD/2)  clk=~clk;
end


encode  u_encode (
    .clk                     ( clk               ),
    .wrregen(wrregen),
    .keyadsel                ( keyadsel  [1:0]   ),

    .intxt                   ( intxt     [127:0] ),
    .roundkey                ( roundkey  [127:0] ),
    .outtxt                  ( outtxt    [127:0] )
);
integer fd,i=0,flag;
initial
begin
    #(PERIOD*2+1);
    wrregen = 1;
    keyadsel=2'b00;
    intxt=128'h3243f6a8885a308d313198a2e0370734;       
    #(PERIOD);

    keyadsel=2'b01;      
    #(PERIOD*9);

    keyadsel=2'b10;
    #(PERIOD);
    
    wrregen = 0 ;
    flag = 1;
    #(PERIOD*10);
   
    $stop;
end

integer fdd;
initial begin
    #(PERIOD*2+1);

    fdd = $fopen("key_en.info","r");
    fd = $fopen("outtxt.info","w");

    while((!$feof(fdd)))begin

        $fscanf(fdd,"%h",roundkey);
        #(PERIOD);
        $fwrite(fd,"%2d %h\n",i,outtxt);i=i+1;
    end
    $fclose(fdd);
    $fclose(fd);
    $stop;
end

endmodule